WITH Ada.Text_IO;
PROCEDURE Lab6 IS
   PACKAGE T_IO RENAMES Ada.Text_IO;

   SUBTYPE QAString IS String(1..40);
   SUBTYPE Answer IS Character RANGE 'a'..'d';

   TYPE QAArray IS ARRAY(Integer RANGE <>) OF QAString;
   TYPE AnswerArray IS ARRAY(Integer RANGE <>) OF Answer;

   In_File : T_IO.File_Type;

   NumQuestions : CONSTANT Integer := 10;
   NumAnswers : CONSTANT Integer := NumQuestions*4;

   QuestionArray : QAArray(1..NumQuestions);
   Answers : AnswerArray(1..NumQuestions);
   PossibleAnswerArray : QAArray(1..NumAnswers);

   CurrentAnswer : Answer;
   OnQuestion : Integer;
   Points : Integer;

BEGIN
   Points := 0;
   OnQuestion := 1;

   T_IO.Open(File => In_File,
             Mode => T_IO.In_File,
             Name => "qa.txt");

   FOR i IN 1..NumQuestions LOOP
      Ada.Text_IO.Get(File => In_File,Item => QuestionArray(i));
      FOR j IN 1..4 LOOP
         Ada.Text_IO.Get(File => In_File,Item => PossibleAnswerArray( (i-1)*4 + j));
      END LOOP;
      Ada.Text_IO.Get(File => In_File, Item => Answers(i));
   END LOOP;

   FOR i IN 1..NumQuestions LOOP
      ada.Text_IO.Put_Line(QuestionArray(i));
      FOR j IN 1..4 LOOP
         Ada.Text_IO.Put_Line(Item => PossibleAnswerArray( (i-1)*4 + j));
      END LOOP;
      LOOP
         BEGIN
            Ada.Text_IO.put("Answer  > ");
            Ada.Text_IO.Get(Item => CurrentAnswer);
            Ada.Text_IO.Skip_Line;
            EXIT;
      	 EXCEPTION
            WHEN OTHERS =>
               Ada.Text_IO.New_Line;
               Ada.Text_IO.Skip_Line;
               Ada.Text_IO.Put_Line("Please enter a letter 'a' through 'd'");
         END;
      END LOOP;
      IF CurrentAnswer = Answers(i) THEN
         Points := Points + 1;
      END IF;
   END LOOP;

   Ada.Text_IO.Put("You got ");
   Ada.Text_IO.Put(Integer'Image(Points));
   Ada.Text_io.Put(" right out of ");
   Ada.Text_IO.Put(Integer'Image(NumQuestions));
   Ada.Text_IO.Put_Line(".");
END Lab6;
